﻿/// <reference path="../../js/utils.js" />
'use strict';

define([
    'backgrid',
    'backgrid.extensions',
    'assets/backgrid/moment-cell/js/moment-cell',
],
function (Backgrid) {
    return {
        grids: {
            travels: {
                all: function (collection) {
                    var momentCenterCellDatetime = Backgrid.Extension.MomentCenterCell.extend({
                        modelFormat: "YYYY-MM-DD HH:mm:ss",
                        //displayLang: "zh-tw",
                        displayFormat: "MMM-DD HH:mm"
                    });

                    return new Backgrid.Grid({
                        row: Backgrid.Extension.ConditionalStyleRow.extend({
                            evaluate: function () {
                                if (!this.model.get('end'))
                                    return 'current-travel-row';
                            },
                        }),
                        columns: [
                            {
                                name: 'number',
                                label: 'Número',
                                cell: 'integer',
                            },
                            {
                                name: 'driver',
                                label: 'Chofer',
                                cell: 'string-center',
                            },
                            {
                                name: 'truck',
                                label: 'Camión',
                                cell: 'string-center',
                            },
                            {
                                name: 'semitruck',
                                label: 'Semi',
                                cell: 'string-center',
                            },
                            {
                                name: 'start',
                                label: 'Fecha Salida',
                                cell: momentCenterCellDatetime,
                            },
                            {
                                name: 'end',
                                label: 'Fecha Llegada',
                                cell: momentCenterCellDatetime,
                            },
                            {
                                name: 'destination',
                                label: 'Destino',
                                cell: 'string-center',
                            },
                            //{
                            //    name: 'distance',
                            //    label: 'Distancia (Km)',
                            //    cell: 'integer',
                            //},
                            {
                                name: 'load',
                                label: 'Carga',
                                cell: 'string-center',
                            },
                            {
                                name: 'pocketMoneyStart',
                                label: 'Saldo Inicial',
                                cell: 'currency',
                            },
                            {
                                name: 'pocketMoneyEnd',
                                label: 'Saldo Final',
                                cell: 'currency',
                            },
                        ],
                        collection: collection,
                    });
                },
                driver: function (collection) {
                    var momentCenterCellDatetime = Backgrid.Extension.MomentCenterCell.extend({
                            modelFormat: "YYYY-MM-DD HH:mm:ss",
                            //displayLang: "zh-tw",
                            displayFormat: "MMM-DD HH:mm"
                        });

                    return new Backgrid.Grid({
                        row: Backgrid.Extension.ConditionalStyleRow.extend({
                            evaluate: function () {
                                if (!this.model.get('end'))
                                    return 'current-travel-row';
                            },
                        }),
                        columns: [
                            {
                                name: 'number',
                                label: 'Número',
                                cell: 'integer',
                            },
                            {
                                name: 'start',
                                label: 'Fecha Salida',
                                cell: momentCenterCellDatetime,
                            },
                            {
                                name: 'end',
                                label: 'Fecha Llegada',
                                cell: momentCenterCellDatetime,
                            },
                            {
                                name: 'destination',
                                label: 'Destino',
                                cell: 'string-center',
                            },
                            //{
                            //    name: 'distance',
                            //    label: 'Distancia (Km)',
                            //    cell: 'integer',
                            //},
                            {
                                name: 'load',
                                label: 'Carga',
                                cell: 'string-center',
                            },
                            {
                                name: 'truck',
                                label: 'Camión',
                                cell: 'string-center',
                            },
                            {
                                name: 'semitruck',
                                label: 'Semi',
                                cell: 'string-center',
                            },
                            {
                                name: 'pocketMoneyStart',
                                label: 'Saldo Inicial',
                                cell: 'currency',
                            },
                            {
                                name: 'pocketMoneyEnd',
                                label: 'Saldo Final',
                                cell: 'currency',
                            },
                        ],
                        collection: collection,
                    });
                },
                truck: function (collection) {
                    var momentCenterCellDatetime = Backgrid.Extension.MomentCenterCell.extend({
                        modelFormat: "YYYY-MM-DD HH:mm:ss",
                        //displayLang: "zh-tw",
                        displayFormat: "MMM-DD HH:mm"
                    });

                    return new Backgrid.Grid({
                        row: Backgrid.Extension.ConditionalStyleRow.extend({
                            evaluate: function () {
                                if (!this.model.get('end'))
                                    return 'current-travel-row';
                            },
                        }),
                        columns: [
                            {
                                name: 'number',
                                label: 'Número',
                                cell: 'integer',
                            },
                            {
                                name: 'start',
                                label: 'Fecha Salida',
                                cell: momentCenterCellDatetime,
                            },
                            {
                                name: 'end',
                                label: 'Fecha Llegada',
                                cell: momentCenterCellDatetime,
                            },
                            {
                                name: 'destination',
                                label: 'Destino',
                                cell: 'string-center',
                            },
                            //{
                            //    name: 'distance',
                            //    label: 'Distancia (Km)',
                            //    cell: 'integer',
                            //},
                            {
                                name: 'load',
                                label: 'Carga (Kg)',
                                cell: 'string-center',
                            },
                            {
                                name: 'driver',
                                label: 'Chofer',
                                cell: 'string-center',
                            },
                        {
                            name: 'semitruck',
                            label: 'Semi',
                            cell: 'string-center',
                        },
                        ],
                        collection: collection,
                    });
                },
            },
            events: {
                driver: function (collection) {
                    var momentCenterCellDate = Backgrid.Extension.MomentCenterCell.extend({
                            modelFormat: "YYYY-MM-DD",
                            //displayLang: "zh-tw",
                            displayFormat: "DD-MMM-YY"
                        });

                    return new Backgrid.Grid({
                        row: Backgrid.Extension.ConditionalStyleRow.extend({
                            evaluate: function () {
                                var status = this.model.get('status');

                                if (status == 1)
                                    return 'event-near-row';
                                else if (status == 2)
                                    return 'event-expired-row';
                            },
                        }),
                        columns: [
                            {
                                name: 'description',
                                label: 'Descripción',
                                cell: 'string-center',
                            },
                            {
                                name: 'nextDatetime',
                                label: 'Vencimiento',
                                cell: momentCenterCellDate,
                            },
                            {
                                name: 'repeatFreq',
                                label: 'Renovación',
                                cell: 'string-center',
                            },                            
                            {
                                name: 'previousDatetime',
                                label: 'Última Renovación',
                                cell: momentCenterCellDate,
                            },
                            {
                                name: 'relining',
                                label: '',
                                cell: Backgrid.Extension.ButtonCell.extend({
                                    buttonLabel: 'Cambiar',
                                    events: {
                                        //click: function () { alert(1); }
                                    },
                                }),
                            },
                            {
                                name: 'notify',
                                label: 'Notificar',
                                cell: 'boolean',
                            },
                            //{
                            //    name: 'reminderDatetime',
                            //    label: 'Recordatorio',
                            //    cell: 'string-center',
                            //},
                        ],
                        collection: collection,
                    });
                },
                truck: function (collection) {
                    var momentCenterCellDate = Backgrid.Extension.MomentCenterCell.extend({
                        modelFormat: "YYYY-MM-DD",
                        //displayLang: "zh-tw",
                        displayFormat: "DD-MMM-YY"
                    });

                    return new Backgrid.Grid({
                    row: Backgrid.Extension.ConditionalStyleRow.extend({
                        evaluate: function () {
                            var status = this.model.get('status');

                            if (status == 1)
                                return 'event-near-row';
                            else if (status == 2)
                                return 'event-expired-row';
                        },
                    }),
                    columns: [
                        {
                            name: 'description',
                            label: 'Descripción',
                            cell: 'string-center',
                        },
                        {
                            name: 'nextDatetime',
                            label: 'Vencimiento',
                            cell: momentCenterCellDate,
                        },
                        {
                            name: 'repeatFreq',
                            label: 'Renovación',
                            cell: 'string-center',
                        },
                        {
                            name: 'previousDatetime',
                            label: 'Última Renovación',
                            cell: momentCenterCellDate,
                        },
                        {
                            name: 'relining',
                            label: '',
                            cell: Backgrid.Extension.ButtonCell.extend({
                                buttonLabel: 'Cambiar',
                                events: {
                                    //click: function () { alert(1); }
                                },
                            }),
                        },
                        {
                            name: 'notify',
                            label: 'Notificar',
                            cell: 'boolean',
                        },
                        //{
                        //    name: 'reminderDatetime',
                        //    label: 'Recordatorio',
                        //    cell: 'string-center',
                        //},
                    ],
                    collection: collection,
                });
                },
            },
        },
    };
});